package com.xxx.servlet;

import com.alibaba.fastjson.JSONObject;
import com.xxx.pojo.Student;
import com.xxx.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/8/10 10:39
 * @Copyright 博为峰
 */
@WebServlet("/ajax")
public class AjaxServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final StudentServiceImpl studentService = new StudentServiceImpl();
        final ArrayList<Student> list = studentService.queryStudents();
        final String jsonString = JSONObject.toJSONString(list);
        resp.getWriter().write(jsonString);
    }
}
